﻿/*	
	stencil - action script 3 isometric game engine.

	http://code.google.com/p/stencilas3/
	
	Copyright (c) 2010 Max Zhuravkov, All Rights Reserved.

	Permission is hereby granted, free of charge, to any person obtaining a copy of
	this software and associated documentation files (the "Software"), to deal in
	the Software without restriction, including without limitation the rights to
	use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
	of the Software, and to permit persons to whom the Software is furnished to do
	so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in all
	copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
	SOFTWARE.
*/
package stencil.core.engine {
	

	[Event(name="stnAddComponent", type="stencil.core.engine.events.ComponentEvent")]
	
	[Event(name="stnRemoveComponent", type="stencil.core.engine.events.ComponentEvent")]
	
	
	/**
	 * 
	 * Defines methods for managing components.
	 * 
	 * @author Max Zhuravkov
	 */
	public interface IComponentList extends IComponent {
		
		/**
		 * @private
		 */
		function set components(value:Array):void;
		
		/**
		 * The array of child components.
		 * 
		 * @private
		 */
		function get components():Array;
		
		/**
		 * Adds the given component. If this component is already added or there is another component with the passed identifier then ArgumentError is thrown.
		 * then ComponentError is thrown.
		 * 
		 * @param	id	the identifier.
		 * @param	component	the component.
		 * @param	data	the component data. Null value indicates that the owner of the component list should be used as data itself.
		 */
		function addComponent(id:String, component:IComponent, data:Object = null):IComponent;
		
		/**
		 * Adds component. If there is another component with the given identifier then ComponentError is thrown.
		 * 
		 * @param	id the identifier.
		 * @param	componentType	the component type.
		 * @param	data	the component data. Null value indicates that the owner of the the component list should be used as data itself.
		 * 
		 * @return
		 */
		function addComponentType(id:String, componentType:Class, data:Object = null):IComponent;
		
		/**
		 * Returns the component with the specified identifier. If no component found Component Error is thrown.
		 * 
		 * @param	id	the identifier.
		 * 
		 * @return	the component with given id.
		 */
		function getComponentById(id:String):IComponent;
		
		
		/**
		 * Returns the component of the given type. If there are more than one component of such type ComponentError is thrown.
		 *
		 * @param	componentType	the component type.
		 * 
		 * @return	the component of the given type.
		 */
		function getComponentByType(componentType:Class):IComponent;
		
		/**
		 * Returns all components of the given type.
		 *
		 * @param	componentType	the component type.
		 * 
		 * @return	components of the given type.
		 */
		function getComponentsByType(componentType:Class):Array;
		
		/**
		 * Returns true if this component list contains the given component.
		 * 
		 * @param	component	the component.
		 * 
		 * @return	true if this component list contains the given component.
		 */
		function containsComponent(component:IComponent):Boolean;
		
		/**
		 * Returns true if this game object has a component of the given type.
		 * 
		 * @param	componentType	the component type.
		 * 
		 * @return	true if this component list contains at least one component of the given type.
		 */
		function containsComponentType(componentType:Class):Boolean;
		
		/**
		 * Removes the component. If this component is not found ComponentError is thrown.
		 * 
		 * @param	component	the component.
		 * 
		 * @return	the removed component.
		 */
		function removeComponent(component:IComponent):IComponent;
		
		/**
		 * Removes component with the given identifier. If such component is not found ComponentError is thrown.
		 * 
		 * @param	id	the identifier.
		 * 
		 * @return	the removed component.
		 */
		function removeComponentById(id:String):IComponent;
		
		/**
		 * Removes component of the given type. If component of such type is not found ComponentError is thrown.
		 * 
		 * @param	componentType	the component type.
		 * 
		 * @return	an array of removed components.
		 */
		function removeComponentsByType(componentType:Class):Array;
		
		/**
		 * Removes all components.
		 */
		function removeAllComponents():Array;
		
	}
	
}